# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Arjan Timmerman <arjan@archlinux.org>
# Contributor: Wael Nasreddine <gandalf@siemens-mobiles.org>
# Contributor: Tor Krill <tor@krill.nu>
# Contributor: Will Rea <sillywilly@gmail.com>

pkgbase=network-manager-applet
pkgname=(network-manager-applet nm-connection-editor)
pkgver=1.24.0
pkgrel=1
pkgdesc="Applet for managing network connections"
url="https://wiki.gnome.org/Projects/NetworkManager/"
arch=(x86_64)
license=(GPL LGPL)
makedepends=(libsecret libnotify libmm-glib gobject-introspection git gtk-doc meson libnma
             libappindicator-gtk3 libgudev)
_commit=2376585a0612c8ea65703cc32f6fb5c4578fbe38  # tags/1.24.0^0
source=("git+https://gitlab.gnome.org/GNOME/network-manager-applet.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgbase
  git describe --tags | sed 's/-dev/dev/;s/-/+/g'
}

prepare() {
  cd $pkgbase
}

build() {
  arch-meson $pkgbase build -D selinux=false
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_network-manager-applet() {
  depends=(nm-connection-editor libmm-glib libnotify libsecret networkmanager
           libappindicator-gtk3)

  meson install -C build --destdir "$pkgdir"

  _pick nmce "$pkgdir"/usr/bin/nm-connection-editor
  _pick nmce "$pkgdir"/usr/share/applications/nm-connection-editor.desktop
  _pick nmce "$pkgdir"/usr/share/icons/hicolor/*/*/nm-device-wwan{,-symbolic}.*
  _pick nmce "$pkgdir"/usr/share/locale
  _pick nmce "$pkgdir"/usr/share/man/man1/nm-connection-editor.1
  _pick nmce "$pkgdir"/usr/share/metainfo
}

package_nm-connection-editor() {
  pkgdesc="NetworkManager GUI connection editor and widgets"
  depends=(libnma)
  conflicts=('libnm-gtk<1.8.18-1')
  replaces=('libnm-gtk<1.8.18-1')
  mv nmce/* "$pkgdir"
}
